package thirdwork.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import thirdwork.dao.UserDao;
import thirdwork.dao.impl.UserImpl;
import thirdwork.domain.User;

/**
 * Servlet implementation class RegistEmployee
 */
@WebServlet("/RegistEmployee")
public class RegistEmployee extends HttpServlet {
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setContentType("text/html;charset=UTF-8");
		resp.setCharacterEncoding("UTF-8");
		User user = new User();
		user.setUsername(req.getParameter("username"));
		user.setPassword(req.getParameter("password"));
		UserDao userdao = new UserImpl();
		int i = userdao.insertUser(user);
		System.out.println("插入" + i + "个用户");
		resp.sendRedirect(req.getContextPath() + "/login.jsp");
	}
}
